package com.yitiao.simple.file;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * 将自己的信息发送给客户端
 */
public class ServerDiscoveryServer {
    public static void main(String[] args) {
        try {
            DatagramSocket socket = new DatagramSocket();
            socket.setBroadcast(true);

            String serverInfo = "ServerIP:127.0.0.1 ServerPort:8888"; // 服务器的信息，包括IP地址和端口号
            byte[] sendData = serverInfo.getBytes();

            DatagramPacket packet = new DatagramPacket(sendData, sendData.length, InetAddress.getByName("255.255.255.255"), 9999);
            socket.send(packet);

            System.out.println("Server discovery signal sent.");

            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
